package com.paimeng.Internetworm;

import com.paimeng.bean.News_info;
import com.paimeng.utils.DBStatement;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * @author: 潘辉
 * @Title: NewsDAO
 * @ProjectName: IRGROUP
 * @Description: 将获取到的爬虫链接存放到数据库中
 * @date: 2021/6/8 16:24
 */
public class NewsDAO {
    public static void insert(NewsUrl newsUrl) throws SQLException {
        Connection con = DBStatement.getDbConnection();
        String sql = "insert into newsurl (id, url,title,hotindex) values (?,?,?,?);";
        assert con != null;
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setString(1,null);
        ps.setString(2,newsUrl.getUrl());
        ps.setString(3,newsUrl.getTitle());
        ps.setString(3,newsUrl.getTitle());
        ps.setInt(4,newsUrl.getHotindex());
        ps.execute();
        con.close();


    }


    public static void insertNewsInfo(News_info news_info) throws SQLException {
        Connection con = DBStatement.getDbConnection();
        String sql = "insert into news_info (id, url, date, srcFrom, content, comment, title,hotindex)\n" +
                "values (?,?,?,?,?,?,?,?);";
        assert con != null;
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setString(1,null);
        ps.setString(2,news_info.getUrl());
        ps.setString(3,news_info.getDate());
        ps.setString(4,news_info.getSrcFrom());
        ps.setString(5,news_info.getContent());
        ps.setString(6,news_info.getComment());
        ps.setString(7,news_info.getTitle());
        ps.setInt(8,news_info.getHotIndex());
        ps.execute();
        con.close();

    }

}
